package com.zhanglu.fun.services.datacenter.user;

import com.zhanglu.fun.services.datacenter.entity.User;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhanglu
 * @description
 * @date 2017/6/11 18:00
 */
@RestController
@Slf4j
public class UserRouter {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "登录", notes = "根据帐号密码进行登录")
    @ApiImplicitParams({ @ApiImplicitParam(name = "username", value = "用户帐号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "用户密码", required = true, dataType = "String", paramType = "query") })
    @ApiResponses({ @ApiResponse(code = 200, message = "请求成功", response = User.class) })
    @GetMapping("/user/private")
    public User getUserByUsernameAndPassword(@RequestParam("username") String username, @RequestParam("password") String password) {
        log.info("getUserByAccount receive params:[username is: {} | password is: {}]", username, password);
        return userService.getUserByUsernameAndPassword(username, password);
    }

    @ApiOperation(value = "查询用户", notes = "测试一下充血模型")
    @ApiImplicitParams({ @ApiImplicitParam(name = "username", value = "用户帐号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "用户密码", required = true, dataType = "String", paramType = "query") })
    @ApiResponses({ @ApiResponse(code = 200, message = "请求成功", response = User.class) })
    @GetMapping("/user/list")
    public List<User> listUser(User user) {
        log.info("listUser receive params:{}", user.toString());
        return user.list();
    }
}
